package o;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.annotation.Nullable;

public final class fui {
    private final String[] ˎ;

    public static final class a {
        final List<String> ˋ = new ArrayList(20);

        a ˏ(String str) {
            int indexOf = str.indexOf(":", 1);
            if (indexOf != -1) {
                return ॱ(str.substring(0, indexOf), str.substring(indexOf + 1));
            }
            if (str.startsWith(":")) {
                return ॱ("", str.substring(1));
            }
            return ॱ("", str);
        }

        public a ˊ(String str, String str2) {
            fui.ˊ(str);
            fui.ˊ(str2, str);
            return ॱ(str, str2);
        }

        a ॱ(String str, String str2) {
            this.ˋ.add(str);
            this.ˋ.add(str2.trim());
            return this;
        }

        public a ˎ(String str) {
            int i = 0;
            while (i < this.ˋ.size()) {
                if (str.equalsIgnoreCase((String) this.ˋ.get(i))) {
                    this.ˋ.remove(i);
                    this.ˋ.remove(i);
                    i -= 2;
                }
                i += 2;
            }
            return this;
        }

        public a ˎ(String str, String str2) {
            fui.ˊ(str);
            fui.ˊ(str2, str);
            ˎ(str);
            ॱ(str, str2);
            return this;
        }

        public String ˋ(String str) {
            for (int size = this.ˋ.size() - 2; size >= 0; size -= 2) {
                if (str.equalsIgnoreCase((String) this.ˋ.get(size))) {
                    return (String) this.ˋ.get(size + 1);
                }
            }
            return null;
        }

        public fui ˊ() {
            return new fui(this);
        }
    }

    fui(a aVar) {
        this.ˎ = (String[]) aVar.ˋ.toArray(new String[aVar.ˋ.size()]);
    }

    private fui(String[] strArr) {
        this.ˎ = strArr;
    }

    @Nullable
    public String ॱ(String str) {
        return ˊ(this.ˎ, str);
    }

    public int ˋ() {
        return this.ˎ.length / 2;
    }

    public String ॱ(int i) {
        return this.ˎ[i * 2];
    }

    public String ˋ(int i) {
        return this.ˎ[(i * 2) + 1];
    }

    public List<String> ˎ(String str) {
        int ˋ = ˋ();
        List list = null;
        for (int i = 0; i < ˋ; i++) {
            if (str.equalsIgnoreCase(ॱ(i))) {
                if (list == null) {
                    list = new ArrayList(2);
                }
                list.add(ˋ(i));
            }
        }
        if (list != null) {
            return Collections.unmodifiableList(list);
        }
        return Collections.emptyList();
    }

    public a ˎ() {
        a aVar = new a();
        Collections.addAll(aVar.ˋ, this.ˎ);
        return aVar;
    }

    public boolean equals(@Nullable Object obj) {
        return (obj instanceof fui) && Arrays.equals(((fui) obj).ˎ, this.ˎ);
    }

    public int hashCode() {
        return Arrays.hashCode(this.ˎ);
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        int ˋ = ˋ();
        for (int i = 0; i < ˋ; i++) {
            stringBuilder.append(ॱ(i)).append(": ").append(ˋ(i)).append("\n");
        }
        return stringBuilder.toString();
    }

    private static String ˊ(String[] strArr, String str) {
        for (int length = strArr.length - 2; length >= 0; length -= 2) {
            if (str.equalsIgnoreCase(strArr[length])) {
                return strArr[length + 1];
            }
        }
        return null;
    }

    public static fui ˋ(String... strArr) {
        int i = 0;
        if (strArr == null) {
            throw new NullPointerException("namesAndValues == null");
        } else if (strArr.length % 2 != 0) {
            throw new IllegalArgumentException("Expected alternating header names and values");
        } else {
            String[] strArr2 = (String[]) strArr.clone();
            for (int i2 = 0; i2 < strArr2.length; i2++) {
                if (strArr2[i2] == null) {
                    throw new IllegalArgumentException("Headers cannot be null");
                }
                strArr2[i2] = strArr2[i2].trim();
            }
            while (i < strArr2.length) {
                String str = strArr2[i];
                String str2 = strArr2[i + 1];
                ˊ(str);
                ˊ(str2, str);
                i += 2;
            }
            return new fui(strArr2);
        }
    }

    static void ˊ(String str) {
        if (str == null) {
            throw new NullPointerException("name == null");
        } else if (str.isEmpty()) {
            throw new IllegalArgumentException("name is empty");
        } else {
            int length = str.length();
            for (int i = 0; i < length; i++) {
                char charAt = str.charAt(i);
                if (charAt <= ' ' || charAt >= '') {
                    throw new IllegalArgumentException(fvg.ˊ("Unexpected char %#04x at %d in header name: %s", Integer.valueOf(charAt), Integer.valueOf(i), str));
                }
            }
        }
    }

    static void ˊ(String str, String str2) {
        if (str == null) {
            throw new NullPointerException("value for name " + str2 + " == null");
        }
        int length = str.length();
        int i = 0;
        while (i < length) {
            char charAt = str.charAt(i);
            if ((charAt > '\u001f' || charAt == '\t') && charAt < '') {
                i++;
            } else {
                throw new IllegalArgumentException(fvg.ˊ("Unexpected char %#04x at %d in %s value: %s", Integer.valueOf(charAt), Integer.valueOf(i), str2, str));
            }
        }
    }
}
